package top.fengleifeng.question;

/**
 * @program: leetcode-test
 * @description:
 * @author: fengleifeng
 * @create: 2020-10-15 20:27
 **/
public class Num55跳跃游戏 {

    class Solution {
        public boolean canJump(int[] nums) {
            if (nums.length <= 1) {
                return true;
            }
            boolean[] b = new boolean[nums.length];
            b[0] = true;
            for (int i = 0; i < nums.length; i++) {
                if (b[i]) {
                    for (int j = 0; j < nums[i]; j++) {
                        if (i + j + 1 >= nums.length) {
                            break;
                        } else {
                            b[i + j + 1] = true;
                        }
                    }
                }
            }
            return b[nums.length - 1];
        }
    }

    public static void main(String[] args) {
        int[] ints = {2,3,1,1,4};
        boolean b = new Num55跳跃游戏().new Solution().canJump(ints);
        System.out.println(b);
    }
}
